package com.qf.bookshop2.service.impl;

import com.qf.bookshop2.mapper.UserMapper;
import com.qf.bookshop2.model.User;
import com.qf.bookshop2.service.UserService;

import com.qf.bookshop2.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User getUserByUsername(String username) {
        return userMapper.selectUserByUsername(username);
    }

    @Override
    public void logic(User user) {
        String salt= UUID.randomUUID().toString().replace("-","");
        //加密之后得到的新密码
        String newPassword = StringUtil.toSHA256(user.getPassword(), salt, 1000);
        user.setPassword(newPassword);
        user.setSalt(salt);


        userMapper.insertUserByUser(user);
    }
}

